package net.inxweb.bluemeerkat.domain.model.glossary;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "TBL_GLS_REL")
public class Relation {
	@Id 
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "REL_ID") 
	private Long id;
	
	@Column(name = "REL_NM", length=50)
	private String name;  
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "REL_ID")
	private Set<GlossaryInstance> glossaryInstances;
	
	public Relation() {
		super();
	}
	
	public Relation(String name) {
		super();
		this.name = name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<GlossaryInstance> getGlossaryInstances() {
		return glossaryInstances;
	}

	public void addGlossary(GlossaryInstance glossaryInstance) {
		if(glossaryInstances == null) {
			glossaryInstances = new HashSet<GlossaryInstance>();
		} 
		glossaryInstances.add(glossaryInstance);
	}  
}
